package com.fengdi.mapper;

import com.fengdi.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    // 新增条目
    @Insert("INSERT INTO article " +
            "(id, title, content, cover_img, state, category_id, create_user, create_time, update_time) " +
            " VALUES (#{id}, #{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})")
    void insertArticle(Article article);

    List<Article> getList(Integer userId, Integer categoryId, String state);

    // 获取文章详情
    @Select("SELECT * FROM article WHERE id=#{id}")
    Article getArticleById(Integer id);

    // 更新文章详情
    @Update("UPDATE article " +
            "SET title=#{title}, content=#{content}, cover_img=#{coverImg}, state=#{state}, " +
            "category_id=#{categoryId}, update_time=#{updateTime} WHERE id=#{id}")
    void updateArticleById(Article article);

    // 删除文章
    @Delete("DELETE FROM article WHERE id=#{id}")
    void deleteArticleById(Integer id);

}
